<template>
	<view>
		<button @click="onSetTimeCall()">单次计时器setTimeout</button>
		<button @click="onSetTimeCallxy()">带参数setTimeout</button>
		<button @click="onTimeoutClear()" type="warn">取消计时器</button>
		<button @click="onInteral()" type="primary">周期打印</button>
		<button @click="onClearInter()" type="warn" plain="true">取消周期打印</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName:'zlm',
				password:'222',
				timeoutID:null,
				count:0,
				interalID:null
			}
		},
		methods: {
			onSetTimeCall(){
				console.log("onSetTimeCall-->");
				//
				
				this.timeoutID=setTimeout(()=>{
					console.log("我延时2秒才会打印");
				},2000)
			},
			onSetTimeCall(name,pwd){
				console.log("onSetTimeCallxy--> name:"+name+",pwd:"+pwd);
				setTimeout((x,y)=>{
					console.log("我可以传参数了> x:"+x+",y:"+y);
				},2000,name,pwd)
			},
			onTimeoutClear(){
				console.log("onTimeoutClear------>定时器被我取消了:"+this.timeoutID);
				clearTimeout(this.timeoutID);
			},
			onInteral(){
				this.timeoutID = setInterval(()=>{
					this.count++;
					console.log("周期打印 count:",this.count);
					
				},1000)
			},
			onClearInter(){
				console.log("onClearInter:",this.interalID);
			}
		}
	}
</script>

<style>
button{
	margin: 30rpx;
}
</style>
